﻿using System;
using System.Collections.Generic;
using System.Data;
using br.com.SistemaChamados.Enum;
using br.com.SistemaChamados.Model;
using br.com.SistemaChamados.QueryManager.Core;
using br.com.SistemaChamados.QueryManager.Core.Behavior;

namespace br.com.SistemaChamados.DAO
{
    public class CallCategoryDAO : GenericDao<CallCategory>
    {
        public static CallCategory getCallCategory(int idCallCategory)
        {
            IDbConnection conn = null;
            CallCategory callCategoryReturn = new CallCategory();
            try
            {
                callCategoryReturn = (CallCategory)QueryManagerPerformer.Select(typeof(CallCategory), "Id", idCallCategory, ConnectionBehavior.CONNECTION_BEHAVIOR_CLOSE_AFTER_OPERATION);
            }
            catch (Exception ex)
            {
                callCategoryReturn = null;
                throw ex;
            }
            finally
            {
                if (conn != null) conn.Close();
            }
            return callCategoryReturn;
        }

        public static List<CallCategory> getCallCategories()
        {
            List<CallCategory> list = new List<CallCategory>();
            try
            {
                list = QueryManagerPerformer.Select(typeof(CallCategory), ConnectionBehavior.CONNECTION_BEHAVIOR_CLOSE_AFTER_OPERATION)
                    .ConvertAll(convertObject);
            }
            catch (Exception ex)
            {
                list = null;
                throw ex;
            }
            return list;
        }

        public static EnumCRUDState InsertCallCategory(CallCategory callCategory)
        {
            EnumCRUDState stateTransaction = EnumCRUDState.SQL_NOTHING;
            try
            {
                QueryManagerPerformer.Insert(callCategory, new string[] { "Id" }, ConnectionBehavior.CONNECTION_BEHAVIOR_CLOSE_AFTER_OPERATION);
                stateTransaction = EnumCRUDState.SQL_SUCCESS;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return stateTransaction;
        }

        public static EnumCRUDState UpdateCallCategory(CallCategory callCategory)
        {
            EnumCRUDState stateTransaction = EnumCRUDState.SQL_NOTHING;
            try
            {
                QueryManagerPerformer.Update(callCategory, "Id", callCategory.Id, ConnectionBehavior.CONNECTION_BEHAVIOR_CLOSE_AFTER_OPERATION);
                stateTransaction = EnumCRUDState.SQL_SUCCESS;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return stateTransaction;
        }

        public static EnumCRUDState DeleteCallCategory(CallCategory callCategory)
        {
            EnumCRUDState stateTransaction = EnumCRUDState.SQL_NOTHING;
            try
            {
                QueryManagerPerformer.Delete(callCategory, ConnectionBehavior.CONNECTION_BEHAVIOR_CLOSE_AFTER_OPERATION);
                stateTransaction = EnumCRUDState.SQL_SUCCESS;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return stateTransaction;
        }
    }
}